<template>
    <view :class="theme_view">
		<!-- 魔方-导航下方 - 插件 -->
		<block v-if="(plugins_fccprouniapp_mofang || null) != null">
			<component-mofang :propData="plugins_fccprouniapp_mofang" propLocation="19"></component-mofang>
		</block>
		<view v-if="category.length > 0" class="model-one padding-sm oh flex-row flex-wrap">
		    <block v-for="(item, index) in category" :key="index">
		        <view class="content-item cp" :data-value="item.id" :data-index="index" @tap="category_event">
		            <view class="padding-sm">
		                <view class="content bg-white border-radius-main">
		                    <image :src="item.icon" mode="aspectFit" class="icon circle"></image>
		                    <view class="text single-text margin-top-sm tc" :class="'text-random-' + (Math.floor(Math.random() * 9) + 1)">{{ item.name }}</view>
		                </view>
		            </view>
		        </view>
		    </block>
			
			<!-- 类型弹层 -->
			<component-popup :propShow="popup_leixing_status" propPosition="bottom" @onclose="popup_leixing_close_event">
			    <view class="padding-horizontal-main padding-top-main bg-white" style="min-height:70vh;">
			        <view class="close oh">
			            <view class="fr" @tap.stop="popup_leixing_close_event">
			                <icon type="clear" size="20"></icon>
			            </view>
			        </view>
			        <view class="plugins-leixing-container padding-bottom-main">
			            <block v-if="(leixing_data || null) != null && leixing_data.length > 0">
			                <block v-for="(item, index) in leixing_data" :key="index">
			                    <view class="item" :data-value="item.id" :data-index="index" @tap="fabu_event">
									<view class="base single-text">
										<block v-if="item.icon != ''">
											<image class="dis-inline-block va-m" :src="item.icon" mode="widthFix"></image>
										</block>
										<block v-else>
											<image class="dis-inline-block va-m" :src="common_static_url+'fabu.png'" mode="widthFix"></image>
										</block>
									    <text class="fw-b dis-inline-block va-m">{{item.name}}</text>
									</view>
			                    </view>
			                </block>
			            </block>
			            <block v-else>
			                <view class="cr-grey tc padding-top-xl padding-bottom-xxxl">暂无可发布的类型</view>
			            </block>
			        </view>
			    </view>
			</component-popup>
		</view>
		<view v-else>
			<!-- 提示信息 -->
			<component-no-data :propStatus="data_list_loding_status"></component-no-data>
		</view>
		
		<!-- 魔方-导航下方 - 插件 -->
		<block v-if="(plugins_fccprouniapp_mofang || null) != null">
			<component-mofang :propData="plugins_fccprouniapp_mofang" propLocation="20"></component-mofang>
		</block>
    </view>
</template>
<script>
    const app = getApp();
    import componentNoData from "@/components/no-data/no-data";
    import componentBottomLine from "@/components/bottom-line/bottom-line";
	import componentPopup from '@/components/popup/popup';
	import componentMofang from "@/components/mofang/mofang";
	var common_static_url = app.globalData.get_static_url('classinfo', true);
    export default {
        data() {
            return {
				theme_view: app.globalData.get_theme_value_view(),
				common_static_url: common_static_url,
				data_bottom_line_status: false,
				data_list_loding_status: 1,
				data_list_loding_msg: '',
				currency_symbol: app.globalData.currency_symbol(),
				data_base: null,
				category: [],
				// 自定义分享信息
				share_info: {},
				popup_leixing_status:false,
				leixing_data:null,
				plugins_fccprouniapp_mofang: null,
            };
        },

        components: {
            componentNoData,
            componentBottomLine,
			componentPopup,
			componentMofang
        },
        
        onLoad(params) {
            uni.setNavigationBarTitle({
                title: '信息发布',
            });
        },

        onShow() {
			app.globalData.page_event_onshow_handle();
            // 数据加载
            this.init();

            // 初始化配置
            this.init_config();
            
            // 分享菜单处理
            app.globalData.page_share_handle();
        },

        // 下拉刷新
        onPullDownRefresh() {
            this.setData({
                data_page: 1
            });
            this.get_data_list(1);
        },

        methods: {
            // 初始化配置
            init_config(status) {
                if ((status || false) == true) {
                    this.setData({
                        currency_symbol: app.globalData.get_config('currency_symbol')
                    });
                } else {
                    app.globalData.is_config(this, 'init_config');
                }
            },

            // 获取数据
            init() {
                var user = app.globalData.get_user_info(this, "init");
                if (user != false) {
					// 获取数据
					this.get_data_list();
                } else {
                    this.setData({
                        data_list_loding_status: 0,
                        data_bottom_line_status: false
                    });
                }
            },

            // 获取数据
            get_data_list(is_mandatory) {
                // 分页是否还有数据
                if ((is_mandatory || 0) == 0) {
                    if (this.data_bottom_line_status == true) {
                        uni.stopPullDownRefresh();
                        return false;
                    }
                }
                
                // 是否加载中
                if(this.data_is_loading == 1) {
                    return false;
                }
                this.setData({
                    data_is_loading: 1,
                    data_list_loding_status: 1
                });
                
                // 加载loding
                uni.showLoading({
                    title: this.$t('common.loading_in_text'),//this.$t('common.loading_in_text')
                });
                
                // 获取数据
                uni.request({
                    url: app.globalData.get_request_url("category", "index", "classinfo"),
                    method: 'POST',
                    data: {},
                    dataType: 'json',
                    success: res => {console.log(res.data);
                        uni.hideLoading();
                        uni.stopPullDownRefresh();
                        if (res.data.code == 0) {
                            var data = res.data.data;
                            this.setData({
                                data_base: data.base || null,
                                category: data.category || [],
								plugins_fccprouniapp_mofang: data.mofang || null,
                                data_list_loding_msg: '',
                                data_list_loding_status: 0,
                                data_bottom_line_status: true,
                            });
                            
                            // 基础自定义分享
                            var title = this.data_base.seo_title || this.data_base.application_name;
                            this.setData({
                                share_info: {
                                    title: title,
                                    desc: this.data_base.seo_desc,
                                    path: '/pages/fcc/classinfo/category/category',
                                    img: (this.slide_list || null) != null && this.slide_list.length > 0 ? this.slide_list[0]['images_url'] : '',
                                },
                            });
                        } else {
                            this.setData({
                                data_bottom_line_status: false,
                                data_list_loding_status: 2,
                                data_list_loding_msg: res.data.msg,
                            });
                        }
						// 分享菜单处理
						app.globalData.page_share_handle(this.share_info);
                    },
                    fail: () => {
                        uni.stopPullDownRefresh();
                        this.setData({
                            data_bottom_line_status: false,
                            data_list_loding_status: 2,
                            data_list_loding_msg: this.$t('common.internet_error_tips'),
                        });
                        app.globalData.showToast(this.$t('common.internet_error_tips'));
                    },
                });
            },
			
			category_event(e){
				//console.log(e);
				/*var value = e.currentTarget.dataset.value;
				var temp_category = this.category;
				for(var i in temp_category)
				{
					if(parseInt(temp_category[i].id) === parseInt(value))
					{
						this.setData({
						    leixing_data: temp_category[i].subgoods,
							popup_leixing_status: true
						});
						
						break;
					}
				}*/
				// 用index来遍历，更快
				var index = e.currentTarget.dataset.index;
				var temp_category = this.category;
				this.setData({
				    leixing_data: temp_category[index].subgoods,
					popup_leixing_status: true
				});
			},
			
			fabu_event(e){
				if(parseInt(this.data_base.is_user_add_classinfo) == 1)
				{
					var value = e.currentTarget.dataset.value;
					app.globalData.url_open('/pages/fcc/classinfo/form/form?gid='+value);
				}else{
					app.globalData.showToast('发布功能已关闭');
				}
			},

            // 弹层关闭
            popup_leixing_close_event(e) {
                this.setData({
                    popup_leixing_status: false
                });
            },

            // url事件
            url_event(e) {
                app.globalData.url_event(e);
            }
        }
    };
</script>
<style>
    @import './category.css';
</style>